package k1_exercise;

public class Loop_hundredYuanBuyHundredChicken {
    /**
     * 百钱买百鸡，有100元钱，要去买100只鸡，公鸡5元一只，母鸡3元一只，小鸡1元3只
     * 问公，母，小鸡各买多少只。提示： a+b+c=100 只,5a+3b+1/3c=100钱
     */
    public static void main(String[] args) {

        //初始化100元钱
        int money = 100;
        int count = 100;

        //初始化三种鸡的单价
        double roosterPrice = 5;
        double henPrice = 3;
        double chickPrice = 1.0/3;

        //第一层循环表示的是公鸡
        for (int rooster = 0; rooster <= money/roosterPrice; rooster++) {
            //第二层循环表示的是母鸡
            for (int hen = 0; hen <= money/henPrice; hen++) {
                //用三种鸡的价格相加如果等于总价就符合条件
                if (roosterPrice*rooster+henPrice*hen+chickPrice*(count-rooster-hen)==money) {
                    System.out.println("公鸡："+rooster+",母鸡："+hen+",小鸡："+(count-rooster-hen));
                }
            }
        }
    }
}
